
package com.epfresh.supplier.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.api.global.BaseApplication;
import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.HomeBuyerNumber;

import multitype.ItemViewBinder;
import multitype.OnRecyclerViewItemClickListener;
import com.epfresh.api.widget.MsgView;
public class HomeBuyerTopViewBinder
    extends ItemViewBinder<HomeBuyerNumber, HomeBuyerTopViewBinder.ViewHolder> implements View.OnClickListener{


    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;

    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_home_buyer_top, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull HomeBuyerNumber post) {
        holder.tv_into_goods.setOnClickListener(this);
        holder.tv_make_agent.setOnClickListener(this);
        holder.tv_order_together.setOnClickListener(this);
        holder.tv_order_agent.setOnClickListener(this);
        holder.tv_title.setText(BaseApplication.getInstance().getStoreName());
        if(post.getGrouponCnt()==null ||post.getGrouponCnt()==0 ){
            holder.msg_together.setVisibility(View.GONE);
        }else {
            holder.msg_together.setVisibility(View.VISIBLE);
            holder.msg_together.setText(""+post.getGrouponCnt());
        }
        if(post.getOrderCnt()==null ||post.getOrderCnt()==0 ){
            holder.msg_agent.setVisibility(View.GONE);
        }else {
            holder.msg_agent.setVisibility(View.VISIBLE);
            holder.msg_agent.setText(""+post.getOrderCnt());
        }
    }

    @Override
    public void onClick(View v) {
        if (onRecyclerViewItemClickListener != null){
            onRecyclerViewItemClickListener.onItemClick(v,0,null);
        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        private View tv_order_together, tv_order_agent, tv_make_agent, tv_into_goods;
        private TextView tv_title;
        private MsgView msg_together,msg_agent;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_order_together = itemView.findViewById(R.id.tv_order_together);
            tv_order_agent = itemView.findViewById(R.id.tv_order_agent);
            tv_make_agent = itemView.findViewById(R.id.tv_make_agent);
            tv_into_goods = itemView.findViewById(R.id.tv_into_goods);
            msg_together = itemView.findViewById(R.id.msg_together);
            msg_agent = itemView.findViewById(R.id.msg_agent);

        }
    }
}
